﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Runtime.InteropServices;

namespace JqlEditor
{
    internal class SoundPlayer
    {
        public const int SND_SYNC = 0x0;
        public const int SND_ASYNC = 0x1;
        public const int SND_NODEFAULT = 0x2;
        public const int SND_MEMORY = 0x4;
        public const int SND_LOOP = 0x8;
        public const int SND_NOSTOP = 0x10;
        public const int SND_NOWAIT = 0x2000;
        public const int SND_ALIAS = 0x10000;
        public const int SND_ALIAS_ID = 0x110000;
        public const int SND_FILENAME = 0x20000;
        public const int SND_RESOURCE = 0x40004;
        public const int SND_PURGE = 0x40;
        public const int SND_APPLICATION = 0x80;

        [DllImport("Winmm.dll", CharSet = CharSet.Auto)]
        private extern static bool PlaySound(string filePath, IntPtr hMod, int flag);

        public static bool Play(string filePath, bool isSynchronized)
        {
            if (!File.Exists(filePath)) return false;

            int Flags = SND_FILENAME | (isSynchronized ? SND_SYNC : SND_ASYNC);

            return PlaySound(filePath, IntPtr.Zero, Flags);
        }
    }
}
